﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace WMLogistics.Model
{
    public class ResponseModel
    {
        private string _issuccess;
        /// <summary>
        /// 返回状态码
        /// </summary>
        public string recode
        {
            get { return _issuccess; }
            set { _issuccess = value; }
        }

        /// <summary>
        /// 初始返回接口响应编码
        /// </summary>
        /// <param name="e"></param>
        public void InitResultState(System.Enum e)
        {
            recode = e.GetHashCode().ToString("D4");
            resmessage = GetEnumDesc(e);
        }
        /// <summary>
        /// 初始返回接口出现异常响应编码
        /// </summary>
        /// <param name="ex"></param>
        public void InitResultState(Exception ex)
        {
            this.InitResultState(StateEnum.Exception);
            this.resmessage = string.Format(this.resmessage, ex.Message);
        }

        /// <summary>
        /// 获取枚举的描述信息
        /// 添加人：季健国
        /// 添加时间：2013-12-02
        /// </summary>
        /// <param name="e">传入枚举对象</param>
        /// <returns>得到对应描述信息</returns>
        public static String GetEnumDesc(System.Enum e)
        {
            var enumInfo = e.GetType().GetField(e.ToString());
            var enumAttributes = (DescriptionAttribute[])enumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return enumAttributes.Length > 0 ? enumAttributes[0].Description : e.ToString();
        }
        /// <summary>
        /// 返回实体数据
        /// </summary>
        public object mod { get; set; }

        private string _message;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string resmessage
        {
            get { return _message; }
            set { _message = value; }
        }

        private string _token;
        /// <summary>
        /// 用户凭证
        /// </summary>
        public string token
        {
            get { return _token; }
            set { _token = value; }
        }

    }

    public class PhoneResponseModel
    {
        private string _issuccess;
        /// <summary>
        /// 返回状态码
        /// </summary>
        public string recode
        {
            get { return _issuccess; }
            set { _issuccess = value; }
        }

        /// <summary>
        /// 初始返回接口响应编码
        /// </summary>
        /// <param name="e"></param>
        public void InitResultState(System.Enum e)
        {
            recode = e.GetHashCode().ToString("D4");
            resmessage = GetEnumDesc(e);
        }
        /// <summary>
        /// 初始返回接口出现异常响应编码
        /// </summary>
        /// <param name="ex"></param>
        public void InitResultState(Exception ex)
        {
            //this.InitResultState(StateEnum.Exception);
            this.recode = StateEnum.Exception.GetHashCode().ToString("D4");
            this.resmessage = string.Format(this.resmessage, ex.Message);
        }

        /// <summary>
        /// 获取枚举的描述信息
        /// 添加人：季健国
        /// 添加时间：2013-12-02
        /// </summary>
        /// <param name="e">传入枚举对象</param>
        /// <returns>得到对应描述信息</returns>
        public static String GetEnumDesc(System.Enum e)
        {
            var enumInfo = e.GetType().GetField(e.ToString());
            var enumAttributes = (DescriptionAttribute[])enumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
            return enumAttributes.Length > 0 ? enumAttributes[0].Description : e.ToString();
        }
        /// <summary>
        /// 返回实体数据
        /// </summary>
        public object mod { get; set; }

        private string _message;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string resmessage
        {
            get { return _message; }
            set { _message = value; }
        }

        private string _token;
        /// <summary>
        /// 用户凭证
        /// </summary>
        public string token
        {
            get { return _token; }
            set { _token = value; }
        }

    }
}
